<?php
/**
 * @page compare_listings Compare Listing
 * 
 * With the release of v1.0.10, we've introduced Compare listings feature which lets your 
 * website visitors to interactively compare several aspects of several listings altogether 
 * at a single page. 
 * 
 * If compare listing configuration is enabled, a checkbox will appear with every listing,
 * if you check it, a sliding bar will appear in footer like this:
 * 
 * @image html compare_listing_footer.jpg
 * 
 * Here's the comparision table when you press the compare button:
 * 
 * @image html compare_table.jpg
 * 
 * 
*  @page rich_snippets Google Rich Snippets
*  
*  Google tries to present users with the most useful and informative search results. 
*  The more information a search result snippet can provide, the easier it is for users to 
*  decide whether that page is relevant to their search. With rich snippets, webmasters 
*  with sites containing structured content-such as review sites or business listings-can 
*  label their content to make it clear that each labeled piece of text represents a certain
*  type of data: for example, a restaurant name, an address, or a rating. See in details 
*  here: http://googlewebmastercentral.blogspot.com/2009/10/help-us-make-web-better-update-on-rich.html
*  
*  This not only spices up your search result but also increases click rate:
*  
*  @image html rich_snippet.jpg
*  
*  Note: Currently Rich snippets are limited to review data only, but it can easily be extended
*  to other data types like:
*  
*  @li Products
*  @li Businesses and organizations
*  
*  @section disable_rich_snippets Disable Rich Snippets
*  
*  This feature is enabled by default. To turn it off:
*  Goto Backend > Settings > Listing, you will see 'Enable rich snippets for listings', uncheck 
*  that configuration.
*  
*  @page listing_config Listing Settings
*  
*   These are listing configurations which can be used to alter various functions related to listings on website globally.
*   
*   @li <b>Allow guest to upload photos on listings</b> - Checking this box will allow guest users to upload pic for listings.
*   @li <b>Disable listing RSS feed</b> - Checking this box will disable rss for new listings. Rss icon is displayed in title bar of browser on home page for latest listings.
*   @li <b>Enable Moderation</b> - Checking this box will send all listings for admin approval instead of publishing them instantly.
*   @li <b>Notify me when new listing is added</b> - Checking this box will send an email to admin whenever a new listing is added.
*   @li <b>Listing image required on listing submission</b> - Checking this box will force users to upload image for listings when adding listing.
*   @li <b>Default View</b> - Table view will display listings in a tabular format on website and Blog view will display listings in a linear format.
*   
*   <b>Blog View</b>
*   @image html blog_view.png 
*   
*   <b>Table View</b>
*   @image html table_view.png
*   @li <b>Listings per page limit</b> - You can set the number of listings to be displayed per page for pages like- category  page, All listings page, %User listings page.
*   @li <b>Only Editors can add listings</b> - Checking this box will restrict normal registered users to add listing.
*   @li <b>Allow poster to edit his listing</b> - Checking this box will allow users to edit the listing added by them.
*   @li <b>Moderate edited listing</b> - Checking this box will send all edited listing for admin approval before publishing them to website.
*   @li <b>Enable comparison for listings</b> - Checking this box will show a compare check box on category pages.
*   @li <b>Enable rich snippets for listings</b> - Checking this box will enable rich snippets. You can read more about it here @ref rich_snippets
*   
*/
App::import('Model','config.BaseConfig');
class ListingConfig extends BaseConfig
{
	var $name = 'ListingConfig';
	var $validate = array(
					'paginate_limit'=>array(
							'rule'=>array('validateLimit'),
							'message'=>'Enter a valid numeric value.'
							),					
					);					
				
	var $cache = true;
	
	var $fieldProperties = array(
							'guest_upload_photo'=>array(
									'group'=>array('add'),
									'label'=>'Allow guest to upload photos on listings',
									'type'=>'checkbox',
									),
							'disable_listing_rss'=>array(
									'label'=>'Disable listing RSS feed',
									'group'=>array('add'),
									'type'=>'checkbox'
									),
							'enable_moderation'=>array(
									'label'=>'Enable Moderation',
									'group'=>array('add'),
									'type'=>'checkbox',
									'default'=>'1'
									),
							'enable_add_listing_admin_alert'=>array(
									'label'=>'Notify me when new listing is added',
									'group'=>array('add'),
									'type'=>'checkbox',
									'default'=>1									
									),
							'view_type'=>array(
									'label'=>'Default View',
									'type'=>'radio',
									'options'=>array(
											'table_view'=>'Tableview',
											'blog_view'=>'Blogview'
											),
									'default'=>'blog_view',
									'group'=>array('add'),
									),
							'paginate_limit'=>array(
									'label'=>'Listings per page limit (max. limit 100)',
									'type'=>'text',
									'class'=>'vsmall_input',
									'group'=>array('add'),
									'default'=>'10'
									),
							'listing_add_only_by_editor'=>array(
									'label'=>'Only Editors can add listings',
									'type'=>'checkbox',
									'group'=>array('add'),
									),
							'allowOwnerEdit'=>array(
									'label'=>"Allow poster to edit his listing",
									"type"=>"checkbox",
									"group"=>array("add"),
									),
							'moderateOwnnerEdit'=>array(
									'label'=>"Moderate edited listing.",
									"type"=>"checkbox",
									"group"=>array("add"),
									),
							'enable_comparison'=>array(
									'label'=>'Enable comparison for listings',
									'type'=>'checkbox',
									'default'=>'1',
									'group'=>array('add'),
									),
							'enable_rich_snippets'=>array(
									'label'=>'Enable rich snippets for listings',
									'type'=>'checkbox',
									'default'=>'1',
									'group'=>array('add'),
									),
                             'snippet_entity' => array(
                                 'label'=>"Type of listings for rich snippet",
                                 'type'=>"select",
                             ),           
							'business_owner'=> array(
									'label'=>'Enable claim listings functionality',
									'type'=>'checkbox',
									'default'=>'0',
									'group'=>array('add'),
									),
							'allow_asset_edit' => array(
								'label'=>"Allow Users to delete images uploaded by them",
								'type' => "checkbox",
								'default'=>"0",
								'group'=> array("add"),
							),
							'flay_text' => array(
									'label'=>"Truncate description on listing view page after ? words.",
									
								),     
                              "allow_listing_delete" => array(
								'label' => "Allow listing poster to delete his listing?",
								'options'=> array("No","Yes"),
								"default" => 0
							),
			'add_review_with_listing' => array(
					'label'=>"Enable adding review along with listing",
					'type' => "checkbox",
					'default'=>"0",
					'group'=> array("add")
			),
			'enable_fb_like' => array(
					'label'=>"Show facebook like button on listing pages",
					'type' => "checkbox",
					'default'=>"0",
					'group'=> array("add")
			)
							);
							
	function validateLimit($data)
	{
		$return = true;
		if(empty($data['paginate_limit']))
		{
			$return = false;
		}
		if(count(explode('.',$data['paginate_limit'])) > 1)
		{
			$return = false;
		}
		if(is_numeric($data['paginate_limit']) == false)
		{
			$return = false;	
		}elseif($data['paginate_limit'] > 100)
		{
			$return = false;
		}
		return $return;
	}

	function initialize()
	{
		$this->setFieldProperties('flay_text', array(
			'options'=>array(__("Never"),50=>"50",100=>"100",250=>"200",500=>"500",750=>"750",1000=>"1000",2000=>"2000",5000=>"5000"),
			'group'=> array("add"),
			'type' => "select",
		));
        $options = array(
            'CreativeWork',
            //'Event',
            //'Intangible',
            'Organization',
            'Person',
            'Place',
            'Product'
        );
        $options = array_combine($options,$options);
        $this->setFieldProperties('snippet_entity', array(
            'options'=>$options,
            'group'=> array("add"),
            'tooltip'=>sprintf(__("Visit this page %s for better understanding"),"<a href='http://schema.org/Thing' target='__blank'>http://schema.org/Thing</a>"),
        ));
        $this->setFieldProperties( 'allow_multiple_categories' , array(
                                  'label' => "Allow multiple categories in listing",
                                  'group' => array('add'),
                                  'type'=>"checkbox",
                                  'default' => 1,    
                          
                              ));
        $this->setFieldProperties('enable_fb_like',array('after'=>__("This would work only if facebook app settings are povided")));
		parent::initialize();
	}
}
?>